home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / xmsif.exe / XMSTEST2.C < prev    next >
C/C++ Source or Header  |  1991-12-08  |  27KB  |  670 lines

  1. /***************************************************************************
  2. *   xmstest2.c                                                             *
  3. *   MODULE:  XMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.0                                                           *
  6. *   DATE:    12/08/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires xmsif.h, testutil.h, and xmstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, Turbo C 2.0, or MSC 6.00A.             *
  12. *                                                                          *
  13. *   Regression test and example for XMSIF. See XMSTEST.C for more detail.  *
  14. *                                                                          *
  15. ***************************************************************************/
  16.  
  17. /*
  18. ** system includes <>
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <dos.h>
  24. #include <string.h>
  25.  
  26.  
  27. /*
  28. ** custom includes ""
  29. */
  30.  
  31. #include "xmsif.h"
  32. #include "xmstest.h"
  33.  
  34. #include "testutil.h"
  35.  
  36.  
  37. /*
  38. ** local #defines
  39. */
  40.  
  41. /*
  42. ** misc: copyright strings, version macros, etc.
  43. */
  44.  
  45. /*
  46. ** typedefs
  47. */
  48.  
  49. /*
  50. ** global variables
  51. */
  52.  
  53. extern int testno;
  54. extern char *gblmsg;
  55.  
  56.  
  57. /*
  58. ** static globals
  59. */
  60.  
  61. /*
  62. ** function prototypes
  63. */
  64.  
  65. static void do_ncopy2_tests(void);
  66.  
  67.  
  68. /*
  69. ** functions
  70. */
  71.  
  72.  
  73. /***************************************************************************
  74. *   FUNCTION: DO_COPY_TESTS                                                *
  75. *                                                                          *
  76. *   DESCRIPTION:                                                           *
  77. *                                                                          *
  78. *       Dispatcher function for copy test functions.                       *
  79. *                                                                          *
  80. *   ENTRY:                                                                 *
  81. *                                                                          *
  82. *       None.                                                              *
  83. *                                                                          *
  84. *   EXIT:                                                                  *
  85. *                                                                          *
  86. *       Void.                                                              *
  87. *                                                                          *
  88. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  89. *                                                                          *
  90. ***************************************************************************/
  91. void do_copy_tests(void)
  92. {
  93.     do_ncopy1_tests();
  94.     do_ncopy2_tests();
  95.     do_icopy_tests();
  96.  
  97.     return;
  98. } /* end of do_copy_tests() */
  99.  
  100.  
  101. /***************************************************************************
  102. *   FUNCTION: DO_NCOPY2_TESTS  (STATIC)                                    *
  103. *                                                                          *
  104. *   DESCRIPTION:                                                           *
  105. *                                                                          *
  106. *       Tests normal copy functions (_XMMcopy() and macros).               *
  107. *                                                                          *
  108. *   ENTRY:                                                                 *
  109. *                                                                          *
  110. *       None.                                                              *
  111. *                                                                          *
  112. *   EXIT:                                                                  *
  113. *                                                                          *
  114. *       Void.                                                              *
  115. *                                                                          *
  116. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  117. *                                                                          *
  118. ***************************************************************************/
  119. static void do_ncopy2_tests(void)
  120. {
  121.     int handle;
  122.     unsigned char far *realbuf;
  123.     unsigned char far *guard1, far *guard2, far *guard3;
  124.     unsigned char far *testbuf;
  125.     unsigned char far *testbuf2;
  126.     int status;
  127.     unsigned long start, stop, total;
  128.     unsigned char huge *temp;
  129.     unsigned long loop;
  130.  
  131.     /* first, allocate some XMS to test with */
  132.     handle = XMMalloc(MINFREE);
  133.     weirdcodechk("XMMalloc", 0, (void far *) NULL, 0, 0);
  134.  
  135.     /* next, allocate a conventional memory buffer */
  136.     realbuf = (unsigned char far *) LMALLOC((MINFREE/1024L) + 3);
  137.     if (realbuf == (unsigned char far *) NULL)
  138.     {
  139.         printf("Can't allocate conventional buffer. Aborting.\n");
  140.         XMMfree(handle);
  141.         exit(3);
  142.     }
  143.  
  144.     /* set up guard zones, etc. */
  145.     guard1 = realbuf;
  146.     FMEMSET(guard1, GUARDVAL, 1024);
  147.     testbuf = (unsigned char far *) normptr(guard1 + 1024);
  148.     guard2 = (unsigned char far *) normptr(testbuf + HALFLEN);
  149.     FMEMSET(guard2, GUARDVAL, 1024);
  150.     testbuf2 = (unsigned char far *) normptr(guard2 + 1024);
  151.     guard3 = (unsigned char far *) normptr(testbuf2 + HALFLEN);
  152.     FMEMSET(guard3, GUARDVAL, 1024);
  153.  
  154.     /* set up patterns */
  155.     farincwordfill(testbuf, HALFLEN, 0);
  156.     FMEMSET(testbuf2, 0, HALFLEN);
  157.     status = XMMcopyto(HALFLEN, testbuf2, handle, 0L);
  158.     TRIPLECHECK("XMMcopyto()", status, 0, (void far *) realbuf, handle, 0);
  159.  
  160.  
  161.     /*
  162.     ** Now, try various copies to EMB, then copy HALFLEN of EMB back to
  163.     ** testbuf2 for checking.
  164.     */
  165.     gblmsg = "  COPY TESTS CONVENTIONAL-EMB";
  166.  
  167.     /* try an even-length copy from offset 0 to offset 0 */
  168.     TESTHEADER();
  169.     printf("XMMcopyto(): even-length copy from offset 0 to offset 0.\n");
  170.     printf("Should succeed.\n");
  171.     status = XMMcopyto(50, testbuf, handle, 0L);
  172.     TRIPLECHECK("XMMcopyto()", status, 0, (void far *) realbuf, handle, 0);
  173.     status = XMMcopyfrom(HALFLEN, handle, 0L, testbuf2);
  174.     TRIPLECHECK("XMMcopyfrom()", status, 0, (void far *) realbuf, handle, 0);
  175.     SRCWORDCHECK(testbuf, HALFLEN);
  176.     GUARDCHECK(handle);
  177.     CPYWORDCHECK(testbuf2, 50);
  178.     ZEROCHECK((testbuf2 + 50), (HALFLEN - 50));
  179.     TESTTAILER();
  180.  
  181.     /* restore destination pattern */
  182.     FMEMSET(testbuf2, 0, HALFLEN);
  183.     status = XMMcopyto(HALFLEN, testbuf2, handle, 0L);
  184.     TRIPLECHECK("XMMcopyto()", status, 0, (void far *) realbuf, handle, 0);
  185.  
  186.     /* try an even-length copy from offset 0 to arbitrary offset */
  187.     TESTHEADER();
  188.     printf("XMMcopyto(): even-length copy from offset 0 to arbitrary offset.\n");
  189.     printf("Should succeed.\n");
  190.     status = XMMcopyto(50, testbuf, handle, 477L);
  191.     TRIPLECHECK("XMMcopyto()", status, 0, (void far *) realbuf, handle, 0);
  192.     status = XMMcopyfrom(HALFLEN, handle, 0L, testbuf2);
  193.     TRIPLECHECK("XMMcopyfrom()", status, 0, (void far *) realbuf, handle, 0);
  194.     GUARDCHECK(handle);
  195.     SRCWORDCHECK(testbuf, HALFLEN);
  196.     ZEROCHECK(testbuf2, 477);
  197.     MEMCMP(testbuf, (testbuf2 + 477), 50);
  198.     ZEROCHECK((testbuf2 + 477 + 50), ((HALFLEN - 477) - 50));
  199.     TESTTAILER();
  200.  
  201.     /* restore destination pattern */
  202.     FMEMSET(testbuf2, 0, HALFLEN);
  203.     status = XMMcopyto(HALFLEN, testbuf2, handle, 0L);
  204.     TRIPLECHECK("XMMcopyto()", status, 0, (void far *) realbuf, handle, 0);
  205.  
  206.     /* try an even-length copy from offset 0 to just before the end */
  207.     TESTHEADER();
  208.     printf("XMMcopyto(): even-length copy from offset 0 to just before end.\n");
  209.     printf("S